package com.hulytu.androidx.adapter.recyclerview;

import android.util.SparseArray;
import android.view.View;


import com.hulytu.android.adapter.ViewHolder;
import com.hulytu.androidx.widget.recyclerview.MockRecyclerView;

import org.jetbrains.annotations.NotNull;

public class BasicViewHolder extends MockRecyclerView.ViewHolder implements ViewHolder {

    private final SparseArray<View> cacheViews = new SparseArray<>(8);

    public BasicViewHolder(@NotNull View itemView) {
        super(itemView);
    }

    @Override
    public @NotNull View getItemView() {
        return itemView;
    }

    @SuppressWarnings("unchecked")
    @Override
    public <V extends View> V findViewById(int viewId) {
        View cacheView = cacheViews.get(viewId);
        if (cacheView == null) {
            V view = itemView.findViewById(viewId);
            cacheViews.put(viewId, view);
            return view;
        }

        return (V) cacheView;
    }
}
